#Copyright 2013 - Bill Dengler
#Clifs is free software: you can redistribute it and/or modify
#it under the terms of the GNU General Public License as published by
#the Free Software Foundation, either version 3 of the License, or
#(at your option) any later version.
#Clifs is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#GNU General Public License for more details.
#You should have received a copy of the GNU General Public License
#along with Clifs.  If not, see http://www.gnu.org/licenses
#imports
import classes
import aircrafts
from sys import exit
import readline

print("Welcome to Clifs!")
#function declarations
def select_aircraft():
    "This function prints out a menu of aircrafts. When a user selects the one they wish to use, a new object of that aircraft class is created and the function returns it."
    #now, we get a list of all of the subclasses of aircraft, which are the aircrafts you can choose from.
    print("populating aircraft list...")
    crafts=classes.aircraft.__subclasses__()
    print("select aircraft : ")
    #use a for loop to print all aircrafts available
    #we have a count variable for keeping track of option numbers, this is for our for loop.
    count=0
    for craftchoice in (crafts):
        print(count," : ",craftchoice.type)
        #add to the count variable for each iteration.
        count = count + 1
    #and now, we ask for input
    chosencraft=int(input("select craft : "))

    #return an instance of the craft for the user
    craft=crafts[chosencraft]()
    return craft
def get_help():
    "This function simply prints a list of commands."
    #we'll populate this function as needed, until we find a better way
    print("commands : ")
    print("quit - quit clifs")
    print("status - print status report")
    print("flaps - toggle flaps")
    print("gear - toggle landing gear")
    print("eval - evaluate python code - debugging purposes only")
    print("nose - control nose wheel")
#now, we actually run clifs itself
#first, get an aircraft
craft=select_aircraft()

#infinite loop that keeps clifs always accepting commands.
while (1):
    cmd = input("Enter command, type ? for help : ")
    if ( cmd == "?" ):
        get_help()
    if ( cmd == "quit" ):
        exit(0)
    if ( cmd == "status" ):
        craft.status()
    if (cmd == "flaps" ):
        craft.flaps.toggle()
    if (cmd == "gear" ):
        craft.gear.toggle()
    if (cmd == "eval"):
        eval(input("Go ahead..."))
    if ( cmd == "nose" ):
        craft.nose.turn()

